//
// ppval.cpp
//
// Code generation for function 'ppval'
//

// Include files
#include "ppval.h"
#include "detrendIBI_priors_data.h"
#include "eml_int_forloop_overflow_check.h"
#include "rt_nonfinite.h"
#include "coder_array.h"
#include "mwmathutil.h"

// Variable Definitions
static emlrtRSInfo yb_emlrtRSI{
    90,      // lineNo
    "ppval", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\lib\\matlab\\polyfun\\ppval.m" // pathName
};

static emlrtRSInfo ac_emlrtRSI{
    136,                 // lineNo
    "scalar_evaluatepp", // fcnName
    "D:\\Program "
    "Files\\MATLAB\\R2022a\\toolbox\\eml\\lib\\matlab\\polyfun\\ppval.m" // pathName
};

// Function Definitions
namespace coder {
real_T ppval(const emlrtStack *sp, const ::coder::array<real_T, 2U> &pp_breaks,
             const ::coder::array<real_T, 2U> &pp_coefs, real_T x)
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack st;
  real_T v;
  int32_T numTerms;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  numTerms = pp_coefs.size(1);
  st.site = &yb_emlrtRSI;
  if (muDoubleScalarIsNaN(x)) {
    v = x;
  } else {
    real_T xloc;
    int32_T high_i;
    int32_T low_i;
    int32_T low_ip1;
    high_i = pp_breaks.size(1);
    low_i = 1;
    low_ip1 = 2;
    while (high_i > low_ip1) {
      int32_T mid_i;
      mid_i = (low_i >> 1) + (high_i >> 1);
      if (((low_i & 1) == 1) && ((high_i & 1) == 1)) {
        mid_i++;
      }
      if (x >= pp_breaks[mid_i - 1]) {
        low_i = mid_i;
        low_ip1 = mid_i + 1;
      } else {
        high_i = mid_i;
      }
    }
    xloc = x - pp_breaks[low_i - 1];
    v = pp_coefs[low_i - 1];
    b_st.site = &ac_emlrtRSI;
    if (pp_coefs.size(1) > 2147483646) {
      c_st.site = &y_emlrtRSI;
      check_forloop_overflow_error(&c_st);
    }
    for (high_i = 2; high_i <= numTerms; high_i++) {
      v = xloc * v +
          pp_coefs[(low_i + (high_i - 1) * (pp_breaks.size(1) - 1)) - 1];
    }
  }
  return v;
}

} // namespace coder

// End of code generation (ppval.cpp)
